const app = getApp()
import util from '../../../utils/util'
import { BuyRecord } from '../../../config/api'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    isEmpty: false,
    type: 2,
    code:'',
    uid:'',
    t:'',
    page: 1,
    limit: 10,
    lists: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let openid = wx.getStorageSync('openid');
    this.setData({
      openid: openid
    })

    this.getLists();
  },

  getLists(){
    let that =this;
    let params= {
      page:that.data.page,
      limit:that.data.limit,
      type: 2,
      openid:that.data.openid
    }
    util.apiRequest(BuyRecord, params,null).then(r => {
      console.log('购买',r)
      if (r.data.data.data.length == 0) {
        that.setData({
          isEmpty: true
        })
      }
      that.setData({
        lists:r.data.data.data
      })
    })
  },

  copyBtn: function (e) {
    var that = this;
    console.log('eee',e)
    let trade_no = e.currentTarget.dataset.trade_no;
    wx.setClipboardData({
      //去找上面的数据
      data: trade_no,
      success: function (res) {
        wx.showToast({
          icon:'none',
          title: '复制成功',
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})